import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:visitor_scan_package/viewmodel/home_scan_view_model.dart';
import 'package:visitor_scan_package/net/account/axun_user.dart';
import 'package:visitor_scan_package/res/color_res.dart';
import 'package:visitor_scan_package/ui/login_page.dart';

class ScanVisitorHomePage extends BaseStatefulMvvmWidget {
  final bool showLogout;

  ScanVisitorHomePage({this.showLogout = true});

  @override
  State<StatefulWidget> createState() => _HomePageState();
}

class _HomePageState extends BaseMvvmState<HomeScanViewModel, ScanVisitorHomePage> {
  @override
  Widget? buildLoadingContentView() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Container(
          height: 45,
        ),
        CommonText('车牌输入', textSize: 20),
        CommonText(
          viewModel.plateNo,
          hintText: '点击输入车牌号',
        ).addToContainer(
            alignment: Alignment.center,
            width: double.infinity,
            height: 72,
            margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 30),
            decoration: BoxDecoration(
                borderRadius: 4.borderRadius,
                border: Border.all(color: const Color(0xffb2b2b2))))
        .onTap(() {
          viewModel.inputPlateNo();
        }),
        // TextButton(
        //   onPressed: () {
        //     viewModel.plateNoScan();
        //   },
        //   child: Row(
        //     mainAxisAlignment: MainAxisAlignment.center,
        //     children: [
        //       const Icon(
        //         Icons.settings_overscan_outlined,
        //         color: ColorRes.main_color,
        //       ),
        //       Container(
        //         width: 10,
        //       ),
        //       CommonText('扫车牌',
        //           fontWeight: FontWeight.bold,
        //           textSize: 20,
        //           textColor: ColorRes.main_color)
        //     ],
        //   ),
        //   style: ButtonStyle(
        //       alignment: Alignment.center,
        //       maximumSize: MaterialStateProperty.all(const Size(190, 64)),
        //       shape: MaterialStateProperty.all(const StadiumBorder(
        //           side: BorderSide(color: ColorRes.main_color)))),
        // ),
        Container(
          height: 80,
        ),
        CommonText('扫码', textColor: Colors.white, textSize: 20)
            .addToContainer(
                width: double.infinity,
                height: 64,
                margin: const EdgeInsets.symmetric(horizontal: 20),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: ColorRes.main_color, borderRadius: 4.borderRadius))
            .onTap(() {
          viewModel.scanCode();
        }),
        Container(height: 25,),
        CommonText('温馨提示：\n若有车辆来访，优先扫描登记车牌，\n再进行访客码核销!',
                textSize: 14, textColor: const Color(0xff939699))
            .addToContainer(
                width: double.infinity,
                margin: const EdgeInsets.symmetric(horizontal: 20,)),
        Container().setWeight(1),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            // Image.asset("images/yyt_logo.png",package: 'visitor_scan_package',),
            // CommonText('颐养通技术支持',textSize: 14,textColor: Color(0xff939699))
          ],
        ).addToContainer(margin: const EdgeInsets.only(bottom: 21))
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          "访客核销",
          style: TextStyle(fontSize: 17, fontWeight: FontWeight.bold),
        ),
        actions:widget.showLogout? [
          CommonText('退出登录', textColor: Color(0xffc0c0c0)).onTap(() {
            AxunUser.clearUser();
            Go().pushAndPop(LoginPage());
          }).addToContainer(
              margin: const EdgeInsets.only(right: 20),
              alignment: Alignment.center)
        ]:[Container()],
      ),
      body: loadingContentWidget,
    );
  }

  @override
  HomeScanViewModel createViewModel() {
    return HomeScanViewModel(context);
  }

  @override
  void onRetryClick() {}

  @override
  void showToast(String msg) {
    // toast.showToast(msg,
    //     textStyle: const TextStyle(color: Colors.white, fontSize: 22),
    //     context: context,
    //     alignment: Alignment.center,
    //     position: toast.StyledToastPosition.center,
    //     animDuration: const Duration(seconds: 0));
    ToastUtils.shotToast(msg, context: context,);
  }
}
